import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author lys
 * 管理员编辑信息页面
 */
public class AdminEditProfile extends JFrame{
    private static AdminEditProfile instance;
    public JLayeredPane jLayeredPane = new JLayeredPane();
    public JPanel jPanel = new JPanel();

    //标签
    private JLabel jLabel1 = new JLabel("修改信息");
    private JLabel jLabel2 = new JLabel(" 用户名 :");
    private JLabel jLabel3 = new JLabel("   姓名 :");
    private JLabel jLabel4 = new JLabel("   学号 :");
    private JLabel jLabel5 = new JLabel(" 新密码 :");
    private JLabel jLabel6 = new JLabel("确认密码:");

    //按钮
    private JButton jButton1 = new JButton("确认修改");
    private JButton jButton2 = new JButton("返回");

    //输入框
    private JTextArea jTextArea = new JTextArea(); //username
    private JTextArea jTextArea1 = new JTextArea(); //name
    private JTextArea jTextArea2 = new JTextArea(); //stuID
    private JPasswordField jPasswordField1 = new JPasswordField();
    private JPasswordField jPasswordField2 = new JPasswordField();

    //字体
    private Font font1 = new Font("宋体",Font.BOLD,60);
    private Font font2 = new Font("宋体",Font.BOLD,40);
    private Font font3 = new Font("宋体",Font.BOLD,30);

    private JPanel jPanel1 = new JPanel();
    private JPanel jPanel2 = new JPanel();
    private JPanel jPanel3 = new JPanel();
    private JPanel jPanel4 = new JPanel();
    private JPanel jPanel5 = new JPanel();

    private Dimension dimension = new Dimension(350, 50);

    private AdminEditProfile() {
        Icon i = new ImageIcon(AdminEditProfile.class.getResource("img/login2.jpg"));
        JLabel Label = new JLabel(i);
        Label.setBounds(0, 0, 800, 800);

        jLabel1.setFont(font1);
        jLabel1.setBounds(280, 50, 300, 80);
        jLabel1.setForeground(Color.white);

        //用户名
        jLabel2.setFont(font2);
        jLabel2.setBounds(150, 200, 200, 50);
        jLabel2.setForeground(Color.white);
        jTextArea.setPreferredSize(new Dimension(350,50));
        jTextArea.setBorder(BorderFactory.createLineBorder(Color.white,3));
        jTextArea.setFont(font2);
        jPanel1.setBounds(0,180,800,60);
        jPanel1.add(jLabel2);
        jPanel1.add(jTextArea);


        //姓名
        jLabel3.setFont(font2);
        jLabel3.setBounds(150, 270, 200, 50);
        jLabel3.setForeground(Color.white);
        //jTextArea1.setLayout(null);
        jTextArea1.setPreferredSize(new Dimension(350,50));
        jTextArea1.setBorder(BorderFactory.createLineBorder(Color.white,3));
        jTextArea1.setFont(font2);
        jTextArea1.setForeground(Color.black);
        jPanel2.setBounds(0,260,800,60);
        jPanel2.add(jLabel3);
        jPanel2.add(jTextArea1);

        //学号
        jLabel4.setFont(font2);
        jLabel4.setBounds(150, 360, 200, 60);
        jLabel4.setForeground(Color.white);
        // jTextArea2.setLayout(null);
        jTextArea2.setPreferredSize(new Dimension(350,50));
        jTextArea2.setBounds(350,340,350,50);
        jTextArea2.setBorder(BorderFactory.createLineBorder(Color.white,3));
        jTextArea2.setFont(font2);
        jTextArea2.setForeground(Color.black);
        jPanel3.setBounds(0,340,800,60);
        jPanel3.add(jLabel4);
        jPanel3.add(jTextArea2);

        //密码
        jLabel5.setFont(font2);
        jLabel5.setBounds(150, 440, 200, 50);
        jLabel5.setForeground(Color.white);
        //jPasswordField1.setLayout(null);
        jPasswordField1.setBounds(350,410,350,50);
        jPasswordField1.setPreferredSize(new Dimension(350,50));
        jPasswordField1.setBorder(BorderFactory.createLineBorder(Color.white,3));
        jPasswordField1.setFont(font2);
        jPasswordField1.setForeground(Color.black);
        jPanel4.setBounds(0,410,800,60);
        jPanel4.add(jLabel5);
        jPanel4.add(jPasswordField1);

        //确认密码
        jLabel6.setFont(font2);
        jLabel6.setBounds(150, 480, 200, 50);
        jLabel6.setForeground(Color.white);
        //jPasswordField2.setLayout(null);
        jPasswordField2.setBounds(350,480,350,50);
        jPasswordField2.setPreferredSize(new Dimension(350,50));
        jPasswordField2.setBorder(BorderFactory.createLineBorder(Color.white,3));
        jPasswordField2.setFont(font2);
        jPasswordField2.setForeground(Color.black);
        jPanel5.setBounds(0,480,800,60);
        jPanel5.add(jLabel6);
        jPanel5.add(jPasswordField2);


        jButton1.setBounds(280,600,300,60);
        jButton1.setFont(font2);
        jButton1.setForeground(Color.white);
        jButton2.setBounds(620,650,100,50);
        jButton2.setForeground(Color.white);
        jButton2.setFont(font3);

        jPanel1.setOpaque(false);
        jPanel2.setOpaque(false);
        jPanel3.setOpaque(false);
        jPanel4.setOpaque(false);
        jPanel5.setOpaque(false);

        jTextArea.setOpaque(false);
        jTextArea1.setOpaque(false);
        jTextArea2.setOpaque(false);
        jPasswordField1.setOpaque(false);
        jPasswordField2.setOpaque(false);

//        jLayeredPane.add(Label);
//        jLayeredPane.add(jLabel1);
//        jLayeredPane.add(jLabel2);
//        jLayeredPane.add(jLabel3);
//        jLayeredPane.add(jLabel4);
//        jLayeredPane.add(jLabel5);
//        jLayeredPane.add(jLabel6);
//        jLayeredPane.add(jButton1);
//        jLayeredPane.add(jButton2);
//
//

//         add(jLabel1);
//         add(jLabel2);
//         add(jLabel3);
//         add(jLabel4);
//         add(jLabel5);
//         add(jLabel6);
//         add(jButton1);
//         add(jButton2);
        add(jLabel1);
        add(jPanel1);
        add(jPanel2);
        add(jPanel3);
        add(jPanel4);
        add(jPanel5);
        add(jButton2);
        add(jButton1);
        add(Label);


        setVisible(true);
        setSize(800,800);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String username = jTextArea.getText();
                String name = jTextArea1.getText();
                String sid = jTextArea2.getText();
                String password1 = jPasswordField1.getText();
                String password2 = jPasswordField2.getText();
                EditProfile.submitEdit(2, username, sid ,name , password1, password2);
                setVisible(false);
                AdminProfile.removeInstance();
                AdminInterface.removeInstance();
                Admin.removeInstance();
                AdminInterface.getInstance().admin.setVisible(true);
            }
        });

        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                AdminInterface.getInstance().admin.setVisible(true);
            }
        });

        jButton1.setFocusPainted(false);
        jButton2.setFocusPainted(false);
    }
    public static AdminEditProfile getInstance() {
        if (instance==null) instance=new AdminEditProfile();
        return instance;
    }
    public static void removeInstance(){
        instance = null;
    }
}
